var PITCHWISE = PITCHWISE || {};
PITCHWISE.map = PITCHWISE.map || {};

PITCHWISE.map = function (options) {
    'use strict';

    //this.authenticated = options.authenticated;
    this.el = {
        'address':$("#address")
    };

    console.log('PITCHWISE.map.options', options);
    this.load();
};
PITCHWISE.map.prototype.events = function () {

};
PITCHWISE.map.prototype.codeAddress = function () {
    var _this = this;
    var address = this.el.address.html();
    this.geocoder.geocode({ 'address':address}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            _this.map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map:_this.map,
                position:results[0].geometry.location
            });
        } else {
            console.log("Geocode was not successful for the following reason: " + status);
        }
    });
};

PITCHWISE.map.prototype.mapInit = function () {
    this.geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
        zoom:13,
        center:latlng,
        mapTypeId:google.maps.MapTypeId.ROADMAP
    }
    this.map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
};

PITCHWISE.map.prototype.init = function () {
    var _this = this;

    this.mapInit();
    this.codeAddress();
};

PITCHWISE.map.prototype.load = function () {
    this.events();
    this.init();
};